package com.hdaccp.ch02

/**
  *
  */

import org.apache.spark.sql.SparkSession

object Demo1 {
  def main(args: Array[String]): Unit = {

  //1.得到SparkSession对象
    val spark = SparkSession.builder()
      .master("local[2]")
      .appName("ch02Demo1App")
      .getOrCreate()

   import spark.implicits._

   val df =  spark.read.json("f:/resources/people.json") ;

  //  df.printSchema()

  //  df.filter($"age" > 21).show()

  //    df.groupBy("age").count().show() ;

    df.createOrReplaceTempView("people")

    df.sqlContext.sql("select * from people").show()

    spark.stop()


  }
}
